const day = require("dayjs");
const { get7Day } = require("./get7day");

const getMiddleDay = (month) => {
  return day(month.format("YYYY-MM") + "-15");
};
const get42Day = (month = "2021-01-01") => {
  // let wek = get7Day();
  /**
   * 1. 获取当前月第一天的信息
   * 2. 获取当前月第一天的一周信息
   * 3. 遍历获取未来4周共5周的信息
   */

  //  let newDate = dayjs(dayjs().format("YYYY-MM") + "-15").add(
  //   newval,
  //   "month"
  // );
  // this.month = newDate.format("YYYY-MM");
  // this.newDate = this.month + "-15";
  // this.monthdays = getdays.get42Day(this.newDate);

  // let day1 = -day().add(month,"month").$D+1;
  // console.log("get42Day,..");
  // console.log(month);

  let day0 = getMiddleDay(day(month));
  let day1 = getMiddleDay(day());
  // console.log("day0", day0);
  // console.log("day1", day1);
  let last = (day0.$y - day1.$y) * 12 + day0.$M - day1.$M;
  // console.log((day0.$y - day1.$y) * 12, day0.$M, day1.$M);
  // console.log(last, "day1");
  // console.log("get42Day,.. over");
  let arr = [];
  // arr = get7Day(day1);
  for (let i = 0; i < 6; i++) {
    let d = day()
      .add(last, "month")
      .startOf("month")
      .add(7 * i, "day")
      .format("YYYY-MM-DD");
    // console.log("day", d);
    arr.push(get7Day(d));
  }
  return arr;
};

module.exports = {
  get42Day,
};
